﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion

namespace TheSpirit
{
    class MainMenuScreen : GameScreen
    {
        #region Declaration

        Texture2D mainTexture;
        Texture2D scenarioTexture;
        Texture2D survivalTexture;
        Texture2D deckTexture;
        Texture2D exitTexture;
        Texture2D makeTexture;

        Rectangle scenarioRect;
        Rectangle survivalRect;
        Rectangle deckRect;
        Rectangle exitRect;
        Rectangle makeRect;

        #endregion


        #region Initialize

        public MainMenuScreen()
        {

        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            mainTexture = content.Load<Texture2D>("MainMenu/MainMenu");
            scenarioTexture = content.Load<Texture2D>("MainMenu/scenario");
            survivalTexture = content.Load<Texture2D>("MainMenu/survival");
            deckTexture = content.Load<Texture2D>("MainMenu/deck");
            exitTexture = content.Load<Texture2D>("MainMenu/exit");
            makeTexture = content.Load<Texture2D>("MainMenu/make");

            int x = 0;
            int y = Constants.HEIGHT - scenarioTexture.Height;
            int w = scenarioTexture.Width;
            int h = scenarioTexture.Height;

            scenarioRect = new Rectangle(x, y, w, h);
            x += w;
            survivalRect = new Rectangle(x, y, w, h);
            x += w;
            deckRect = new Rectangle(x, y, w, h);
            x += w;
            exitRect = new Rectangle(x, y, w, h);
            x += w;
            makeRect = new Rectangle(x, y, w, h);
        }

        #endregion


        #region Update & Draw

        public override void HandleInput()
        {
            InputManager.ChangeMouseCursor("Normal");

            if (Collision.IntersectPixels(InputManager.MousePosition, Collision.ExtractColor(InputManager.MouseTexture()),
                scenarioRect, Collision.ExtractColor(scenarioTexture)))
            {
                InputManager.ChangeMouseCursor("Select");

                if (InputManager.IsLeftClicked())
                {
                    ExitScreen();

                    ScreenManager.AddScreen(new StrategyScreen());
                    //ScreenManager.AddScreen(new FieldScreen());
                    InputManager.ChangeMouseCursor("Normal");

                    return;
                }
            }
            else if (Collision.IntersectPixels(InputManager.MousePosition, Collision.ExtractColor(InputManager.MouseTexture()),
                survivalRect, Collision.ExtractColor(survivalTexture)))
            {
                InputManager.ChangeMouseCursor("Select");

                if (InputManager.IsLeftClicked())
                {
                    //ExitScreen();

                    //InputManager.ChangeMouseCursor("Normal");

                    return;
                }
            }
            else if (Collision.IntersectPixels(InputManager.MousePosition, Collision.ExtractColor(InputManager.MouseTexture()),
                deckRect, Collision.ExtractColor(deckTexture)))
            {
                InputManager.ChangeMouseCursor("Select");

                if (InputManager.IsLeftClicked())
                {
                    //ExitScreen();

                    //InputManager.ChangeMouseCursor("Normal");

                    return;
                }
            }
            else if (Collision.IntersectPixels(InputManager.MousePosition, Collision.ExtractColor(InputManager.MouseTexture()),
                exitRect, Collision.ExtractColor(exitTexture)))
            {
                InputManager.ChangeMouseCursor("Select");

                if (InputManager.IsLeftClicked())
                {
                    ScreenManager.Game.Exit();

                    return;
                }
            }
            else if (Collision.IntersectPixels(InputManager.MousePosition, Collision.ExtractColor(InputManager.MouseTexture()),
                makeRect, Collision.ExtractColor(makeTexture)))
            {
                InputManager.ChangeMouseCursor("Select");

                if (InputManager.IsLeftClicked())
                {
                    //ExitScreen();

                    //InputManager.ChangeMouseCursor("Normal");

                    return;
                }
            }
        }

        public override void Draw(GameTime gameTime)
        {
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            
            spriteBatch.Begin();

            spriteBatch.Draw(mainTexture, 
                new Rectangle(0, 0, viewport.Width, viewport.Height), 
                Color.White);
            spriteBatch.Draw(scenarioTexture, scenarioRect, Color.White);
            spriteBatch.Draw(survivalTexture, survivalRect, Color.White);
            spriteBatch.Draw(deckTexture, deckRect, Color.White);
            spriteBatch.Draw(exitTexture, exitRect, Color.White);
            spriteBatch.Draw(makeTexture, makeRect, Color.White);


            spriteBatch.End();
        }

        #endregion

    }
}
